package info.yaohua;

import info.bean.Ac02;
import info.dao.Ac01Dao;
import info.dao.JiaTiaoDao;
import info.util.SessionNull;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

//import org.apache.jasper.tagplugins.jstl.core.Choose;

public class BanServlet extends HttpServlet
	{

		@Override
		protected void doGet(HttpServletRequest req, HttpServletResponse resp)
				throws ServletException, IOException
			{
				// TODO Auto-generated method stub
				HttpSession session = req.getSession(false);
				if (session == null)
					{
						SessionNull.forwordTo(req, resp);
					}
				else
					{
						JiaTiaoDao jiaTiaoDao = new JiaTiaoDao();
						Ac01Dao ac01Dao = new Ac01Dao();
						String para = req.getParameter("para");
						String message = (String) req.getAttribute("message");
						Ac02 ac02 = (Ac02) session.getAttribute("ac02");
						int b_id = ac02.getB_id();
						switch (para)
							{
							case "ds":
								try
									{
										ArrayList list_jiatiao = jiaTiaoDao
												.findJiaTiaoByBan("ds", b_id);
										ArrayList list_ac01 = ac01Dao
												.findAc01ByJiaTiaoList(list_jiatiao);
										int count = list_jiatiao.size() - 1;
										req.setAttribute("count", count);
										req.setAttribute("list_jiatiao",
												list_jiatiao);
										req.setAttribute("list_ac01", list_ac01);
										req.setAttribute("disabled", "");
										req.setAttribute("message", message);
										RequestDispatcher view = req
												.getRequestDispatcher("/ban_q.jsp");
										view.forward(req, resp);
									}
								catch (NamingException | SQLException e)
									{
										// TODO Auto-generated catch block
										e.printStackTrace();
									}
								break;

							case "ys":
								try
									{
										ArrayList list_jiatiao = jiaTiaoDao
												.findJiaTiaoByBan("ys", b_id);
										ArrayList list_ac01 = ac01Dao
												.findAc01ByJiaTiaoList(list_jiatiao);
										int count = list_jiatiao.size() - 1;
										req.setAttribute("count", count);
										req.setAttribute("list_jiatiao",
												list_jiatiao);
										req.setAttribute("list_ac01", list_ac01);
										req.setAttribute("disabled",
												"disabled='disabled'");
										RequestDispatcher view = req
												.getRequestDispatcher("/ban_q.jsp");
										view.forward(req, resp);
									}
								catch (NamingException | SQLException e)
									{
										// TODO Auto-generated catch block
										e.printStackTrace();
									}
								break;

							case "dx":
								try
									{
										ArrayList list_jiatiao = jiaTiaoDao
												.findJiaTiaoByBan("dx", b_id);
										ArrayList list_ac01 = ac01Dao
												.findAc01ByJiaTiaoList(list_jiatiao);
										int count = list_jiatiao.size() - 1;
										req.setAttribute("count", count);
										req.setAttribute("list_jiatiao",
												list_jiatiao);
										req.setAttribute("list_ac01", list_ac01);
										req.setAttribute("disabled", "");
										RequestDispatcher view = req
												.getRequestDispatcher("/ban_x.jsp");
										view.forward(req, resp);
									}
								catch (NamingException | SQLException e)
									{
										// TODO Auto-generated catch block
										e.printStackTrace();
									}
								break;

							case "yx":
								try
									{
										ArrayList list_jiatiao = jiaTiaoDao
												.findJiaTiaoByBan("yx", b_id);
										ArrayList list_ac01 = ac01Dao
												.findAc01ByJiaTiaoList(list_jiatiao);
										int count = list_jiatiao.size() - 1;
										req.setAttribute("count", count);
										req.setAttribute("list_jiatiao",
												list_jiatiao);
										req.setAttribute("list_ac01", list_ac01);
										req.setAttribute("disabled",
												"disabled='disabled'");
										RequestDispatcher view = req
												.getRequestDispatcher("/ban_x.jsp");
										view.forward(req, resp);
									}
								catch (NamingException | SQLException e)
									{
										// TODO Auto-generated catch block
										e.printStackTrace();
									}
								break;
							default:
								break;
							}
					}

			}

		@Override
		protected void doPost(HttpServletRequest req, HttpServletResponse resp)
				throws ServletException, IOException
			{
				// TODO Auto-generated method stub
				super.doPost(req, resp);
			}

	}
